package vanjalee.bs.com.control.model;

import java.util.Comparator;

public class Weapon extends Item {

	private String name;
	private int level;
	private int range;
	private int minDmg;
	private int maxDmg;
	private int avgDmg;
	private int weight;
	private int dmgWeight;
	private int slowdown;
	private int equipLimit;

	private WeaponType weaponType;
	
	public Weapon() {
	}

	public Weapon(String name, int level, int range, int minDmg, int maxDmg,
			int avgDmg, int weight, int dmgWeight, int slowdown,
			int equipLimit, String whereToGet, String furtherInfo,
			ItemType itemType, WeaponType weaponType, boolean upgradable,
			boolean special) {
		this.name = name;
		this.level = level;
		this.range = range;
		this.minDmg = minDmg;
		this.maxDmg = maxDmg;
		this.avgDmg = avgDmg;
		this.weight = weight;
		this.dmgWeight = dmgWeight;
		this.slowdown = slowdown;
		this.equipLimit = equipLimit;
		this.whereToGet = whereToGet;
		this.furtherInfo = furtherInfo;
		this.weaponType = weaponType;
		this.itemType = itemType;
		this.upgradable = upgradable;
		this.special = special;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public int getLevel() {
		return level;
	}

	public void setLevel(int level) {
		this.level = level;
	}

	public int getRange() {
		return range;
	}

	public void setRange(int range) {
		this.range = range;
	}

	public int getMinDmg() {
		return minDmg;
	}

	public void setMinDmg(int minDmg) {
		this.minDmg = minDmg;
	}

	public int getMaxDmg() {
		return maxDmg;
	}

	public void setMaxDmg(int maxDmg) {
		this.maxDmg = maxDmg;
	}

	public int getAvgDmg() {
		return avgDmg;
	}

	public void setAvgDmg(int avgDmg) {
		this.avgDmg = avgDmg;
	}

	public int getWeight() {
		return weight;
	}

	public void setWeight(int weight) {
		this.weight = weight;
	}

	public int getDmgWeight() {
		return dmgWeight;
	}

	public void setDmgWeight(int dmgWeight) {
		this.dmgWeight = dmgWeight;
	}

	public int getSlowdown() {
		return slowdown;
	}

	public void setSlowdown(int slowdown) {
		this.slowdown = slowdown;
	}

	public int getEquipLimit() {
		return equipLimit;
	}

	public void setEquipLimit(int equipLimit) {
		this.equipLimit = equipLimit;
	}

	public WeaponType getWeaponType() {
		return weaponType;
	}

	public void setWeaponType(WeaponType weaponType) {
		this.weaponType = weaponType;
	}

	@Override
	public String toString() {
		return "Weapon [name=" + name + ", level=" + level
				+ ", range=" + range + ", minDmg=" + minDmg + ", maxDmg="
				+ maxDmg + ", avgDmg=" + avgDmg + ", weight=" + weight
				+ ", dmgWeight=" + dmgWeight + ", slowdown=" + slowdown
				+ ", equipLimit=" + equipLimit + ", weaponType=" + weaponType
				+ ", itemType=" + itemType + ", whereToGet=" + whereToGet
				+ ", furtherInfo=" + furtherInfo + ", upgradable=" + upgradable
				+ ", special=" + special + "]";
	}

	public static Comparator<Weapon> getComparator(
			SortParameter... sortParameters) {
		return new WeaponComparator(sortParameters);
	}

	public enum SortParameter {
		NAME_ASCENDING, NAME_DESCENDING, LEVEL_ASCENDING, LEVEL_DESCENDING, RANGE_ASCENDING, RANGE_DESCENDING, MINDMG_ASCENDING, MINDMG_DESCENDING, MAXDMG_ASCENDING, MAXDMG_DESCENDING, AVGDMG_ASCENDING, AVGDMG_DESCENDING, WEIGHT_ASCENDING, WEIGHT_DESCENDING, DMGWEIGHT_ASCENDING, DMGWEIGHT_DESCENDING, SLOWDOWN_ASCENDING, SLOWDOWN_DESCENDING, EQUIPLIMIT_ASCENDING, EQUIPLIMIT_DESCENDING, ITEMTYPE_ASCENDING, ITEMTYPE_DESCENDING, WHERETOGET_ASCENDING, WHERETOGET_DESCENDING, FURTHERINFO_ASCENDING, FURTHERINFO_DESCENDING, UPGRADABLE_ASCENDING, UPGRADABLE_DESCENDING, SPECIAL_ASCENDING, SPECIAL_DESCENDING
	}

	private static class WeaponComparator implements Comparator<Weapon> {

		private SortParameter[] parameters;

		private WeaponComparator(SortParameter[] parameters) {
			this.parameters = parameters;
		}

		@Override
		public int compare(Weapon weapon1, Weapon weapon2) {
			int comparison;
			for (SortParameter parameter : parameters) {
				switch (parameter) {
				case NAME_ASCENDING:
					comparison = weapon1.name.compareTo(weapon2.name);
					if (comparison != 0)
						return comparison;
					break;
				case NAME_DESCENDING:
					comparison = weapon2.name.compareTo(weapon1.name);
					if (comparison != 0)
						return comparison;
					break;

				case LEVEL_ASCENDING:
					comparison = ((Integer) weapon1.level)
							.compareTo(weapon2.level);
					if (comparison != 0)
						return comparison;
					break;
				case LEVEL_DESCENDING:
					comparison = ((Integer) weapon2.level)
							.compareTo(weapon1.level);
					if (comparison != 0)
						return comparison;
					break;

				case RANGE_ASCENDING:
					comparison = ((Integer) weapon1.range)
							.compareTo(weapon2.range);
					if (comparison != 0)
						return comparison;
					break;
				case RANGE_DESCENDING:
					comparison = ((Integer) weapon2.range)
							.compareTo(weapon1.range);
					if (comparison != 0)
						return comparison;
					break;

				case MINDMG_ASCENDING:
					comparison = ((Integer) weapon1.minDmg)
							.compareTo(weapon2.minDmg);
					if (comparison != 0)
						return comparison;
					break;
				case MINDMG_DESCENDING:
					comparison = ((Integer) weapon2.minDmg)
							.compareTo(weapon1.minDmg);
					if (comparison != 0)
						return comparison;
					break;

				case MAXDMG_ASCENDING:
					comparison = ((Integer) weapon1.maxDmg)
							.compareTo(weapon2.maxDmg);
					if (comparison != 0)
						return comparison;
					break;
				case MAXDMG_DESCENDING:
					comparison = ((Integer) weapon2.maxDmg)
							.compareTo(weapon1.maxDmg);
					if (comparison != 0)
						return comparison;
					break;

				case AVGDMG_ASCENDING:
					comparison = ((Integer) weapon1.avgDmg)
							.compareTo(weapon2.avgDmg);
					if (comparison != 0)
						return comparison;
					break;
				case AVGDMG_DESCENDING:
					comparison = ((Integer) weapon2.avgDmg)
							.compareTo(weapon1.avgDmg);
					if (comparison != 0)
						return comparison;
					break;

				case WEIGHT_ASCENDING:
					comparison = ((Integer) weapon1.weight)
							.compareTo(weapon2.weight);
					if (comparison != 0)
						return comparison;
					break;
				case WEIGHT_DESCENDING:
					comparison = ((Integer) weapon2.weight)
							.compareTo(weapon1.weight);
					if (comparison != 0)
						return comparison;
					break;

				case DMGWEIGHT_ASCENDING:
					comparison = ((Integer) weapon1.dmgWeight)
							.compareTo(weapon2.dmgWeight);
					if (comparison != 0)
						return comparison;
					break;
				case DMGWEIGHT_DESCENDING:
					comparison = ((Integer) weapon2.dmgWeight)
							.compareTo(weapon1.dmgWeight);
					if (comparison != 0)
						return comparison;
					break;

				case SLOWDOWN_ASCENDING:
					comparison = ((Integer) weapon1.slowdown)
							.compareTo(weapon2.slowdown);
					if (comparison != 0)
						return comparison;
					break;
				case SLOWDOWN_DESCENDING:
					comparison = ((Integer) weapon2.slowdown)
							.compareTo(weapon1.slowdown);
					if (comparison != 0)
						return comparison;
					break;

				case EQUIPLIMIT_ASCENDING:
					comparison = ((Integer) weapon1.equipLimit)
							.compareTo(weapon2.equipLimit);
					if (comparison != 0)
						return comparison;
					break;
				case EQUIPLIMIT_DESCENDING:
					comparison = ((Integer) weapon2.equipLimit)
							.compareTo(weapon1.equipLimit);
					if (comparison != 0)
						return comparison;
					break;

				case WHERETOGET_ASCENDING:
					comparison = weapon1.whereToGet
							.compareTo(weapon2.whereToGet);
					if (comparison != 0)
						return comparison;
					break;
				case WHERETOGET_DESCENDING:
					comparison = weapon2.whereToGet
							.compareTo(weapon1.whereToGet);
					if (comparison != 0)
						return comparison;
					break;

				case FURTHERINFO_ASCENDING:
					comparison = weapon1.furtherInfo
							.compareTo(weapon2.furtherInfo);
					if (comparison != 0)
						return comparison;
					break;
				case FURTHERINFO_DESCENDING:
					comparison = weapon2.furtherInfo
							.compareTo(weapon1.furtherInfo);
					if (comparison != 0)
						return comparison;
					break;

				case ITEMTYPE_ASCENDING:
					comparison = weapon1.itemType.name().compareTo(
							weapon2.itemType.name());
					if (comparison != 0)
						return comparison;
					break;
				case ITEMTYPE_DESCENDING:
					comparison = weapon2.itemType.name().compareTo(
							weapon1.itemType.name());
					if (comparison != 0)
						return comparison;
					break;

				case UPGRADABLE_ASCENDING:
					comparison = ((Boolean) weapon1.upgradable)
							.compareTo(weapon2.upgradable);
					if (comparison != 0)
						return comparison;
					break;
				case UPGRADABLE_DESCENDING:
					comparison = ((Boolean) weapon2.upgradable)
							.compareTo(weapon1.upgradable);
					if (comparison != 0)
						return comparison;
					break;

				case SPECIAL_ASCENDING:
					comparison = ((Boolean) weapon1.special)
							.compareTo(weapon2.special);
					if (comparison != 0)
						return comparison;
					break;
				case SPECIAL_DESCENDING:
					comparison = ((Boolean) weapon2.special)
							.compareTo(weapon1.special);
					if (comparison != 0)
						return comparison;
					break;

				default:
					break;
				}

			}
			return 0;
		}
	}
}
